<%@ page language="java" import="java.util.*,ll.sms.pojo.*,ll.sms.web.*" pageEncoding="UTF-8"%>
<%@page import="ll.sms.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
SmsAdmin smsadmin = (SmsAdmin)session.getAttribute("user");
String username = smsadmin.getAuname();

String defaultChannelId = SmsUtil.sessionHelper(session,AdminProperty.adefaultchannel);
List<ChannelCombox> list1 = SmsUtil.getChannelList(defaultChannelId);


 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>系统菜单</title>
        <link rel="stylesheet" href="../sys/Styles/Base.css" type="text/css"/>
        <link rel="stylesheet" href="../sys/Styles/BreadCrumb.css" type="text/css"/>
        <link rel="stylesheet" type="text/css" href="../ext/sms.css" />
        <link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
        <script src="../sys/js/jquery.js" type="text/javascript" language="JavaScript"></script>
        <script src="../sys/js/jquery.easing.1.3.js" type="text/javascript" language="JavaScript"></script>
        <script src="../sys/js/jquery.dimensions.js" type="text/javascript" language="JavaScript"></script>
        <script src="../sys/js/jquery.jBreadCrumb.js" type="text/javascript" language="JavaScript"></script>
		<script type="text/javascript" src="../ext/ext-base.js"></script>
		<script type="text/javascript" src="../ext/ext-all.js"></script>
        <script type="text/javascript">
            jQuery(document).ready(function()
            {
                jQuery("#breadCrumb0").jBreadCrumb();
                jQuery("#breadCrumb1").jBreadCrumb();
                jQuery("#breadCrumb2").jBreadCrumb();
                jQuery("#breadCrumb3").jBreadCrumb();
                jQuery("#breadCrumb4").jBreadCrumb();
            })
        </script>
		<style type="text/css">
		 .red-row .x-grid3-cell-inner{
		     color:red;
		 }
		</style>
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../images/s.gif';
</script>
<script type="text/javascript">

Ext.onReady(function(){

    var win;
    var win_suggest;
    var winp;
    var button = Ext.get('show-btn');
	var winu;

	var form  = new Ext.form.FormPanel({
	lableAlign:'right',
	url:'../ajaxjsp/system.jsp?flag=changepassword',
	//lablewidth:'50',
	frame:true,
	defaultType:'textfield',
	items:[{
		fieldLabel:'新密码',
		name:'npwd',
		vtype:'alphanum',
        vtypeText:'密码只能包括字母或者数字',
        inputType : 'password'
	},{
		fieldLabel:'重新输入新密码',
		name:'renpwd',
		vtype:'alphanum',
        vtypeText:'密码只能包括字母或者数字',
        inputType : 'password'
	}
	]
	});
    button.on('click', function(){
        if(!win){
            win = new Ext.Window({
                title: '密码修改',
                applyTo     : 'changepassword',
                layout      : 'fit',
                width       : 300,
                height      : 150,
                closeAction :'hide',
                plain       : true,
                items       : [form],

                buttons: [{
                    text     : '提交',
                    handler  : function(){
                    form.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						 Ext.Msg.alert('成功',action.result.msg);
						 win.hide();
					},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误',action.result.errors.msg);
							}else{
							Ext.MessageBox.alert('错误','操作失败');
							}
					}
				});

                    }

                },{
                    text     : '关闭',
                    handler  : function(){
                        win.hide();
                    }
                }]
            });
        }
        win.show(button);
    });
//end win

<%if(username.equals("admin")){%>
//******************admin only********************
    var button_showsuggest = Ext.get('show-suggest');
	var auto_proxy =  Ext.get('auto-pbtn');
	var auto_user =  Ext.get('auto-ubtn');

	//suggest begin
	var SuggestRecord = Ext.data.Record.create([
	    {name: 'sid', type: 'string'},
        {name: 'suname', type: 'string'},
        {name: 'stype', type: 'string'},
        {name: 'scontent', type: 'string'},
        {name: 'saddtime', type: 'string'}

    ]);

 var store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/system.jsp?flag=suggest'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },SuggestRecord),
        remoteSort: true
    });

   var sm = new Ext.grid.CheckboxSelectionModel();
   sm.handleMouseDown = Ext.emptyFn;

    var columns = new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),
        sm,
        {header: '反馈者', dataIndex: 'suname'},
        {header: '类型', dataIndex: 'stype'},
        {header: '内容', dataIndex: 'scontent'},
        {header: '添加时间', dataIndex: 'saddtime'}
    ]);

       columns.defaultSortable = true;

        var grid = new Ext.grid.EditorGridPanel({
        loadMask: true,
        store: store,
        cm: columns,
       // height : 400,
       // margins: '2 2 2 2',
        columnWidth : .5,
        sm: sm,
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: store,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        }),
        tbar: new Ext.Toolbar({
        items:[
               {
                    id:'del'
                    ,text:"删除"
                    ,handler: function(){
                    doGrid();
                    }
                }

            ]
        })
    });

    store.load({params:{start:0,limit:15}});

	var doGrid =function (){

        var rows = grid.getSelectionModel().getSelections();
        if (rows.length == 0) {
            Ext.MessageBox.alert('警告', '最少选择一条信息，进行操作!');
        }
        else {
            Ext.MessageBox.confirm('提示框', '您确定要进行该操作？', function(btn){
                if (btn == 'yes') {
                var delid='';
                    for (var i = 0; i < rows.length; i++) {
                        delid=delid+rows[i].get('sid')+'^';
                    }

                 Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp?flag=suggestdel',
                  method : 'POST',
                  params : {
                      //delid : delid
                      delid : '123'
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								grid.getStore().reload({params:{start:0,limit:15}});

                            }
                            else{
                                Ext.Msg.alert('失败','删除操作失败');
                            }
                         }
              });
                }
            });
        }
    }
//end grid

button_showsuggest.on('click', function(){

        if(!win_suggest){
            win_suggest = new Ext.Window({
             	title: '意见或建议列表',
                applyTo     : 'show-suggest-div',
                layout      : 'fit',
                width       : 500,
                height      : 400,
                closeAction :'hide',
                plain       : true,
                items       : [grid],

                 buttons: [
					{
                    text     : '关闭',
                    handler  : function(){ win_suggest.hide();}
                    }
				]
            });
        }
        win_suggest.show(button_showsuggest);
    });
//end suggest

//****************************begin proxy*****************
var AdminRecord = Ext.data.Record.create([
	        {name: 'aid', type: 'string'},
	        {name: 'auname', type: 'string'},
	        {name: 'apwd', type: 'string'},
	        {name: 'acompany', type: 'string'},
	        {name: 'aregisttime', type: 'string'},
	        {name: 'arank', type: 'int'},
	        {name: 'asmsnum', type: 'int'},
	        {name: 'aavailable', type: 'int'},
            {name: 'aaddress', type: 'string'},
            {name: 'aphone', type: 'string'},
            {name: 'alinkman', type: 'string'},
            {name: 'alinkmanphone', type: 'string'},
            {name: 'alinkmanqq', type: 'string'},
            {name: 'adefaultchannel', type: 'string'}

    ]);

    var proxystore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/proxtlist.jsp?flag=fuckcreator'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },AdminRecord),
        remoteSort: true
    });

    var pcolumns = new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),
        {header: '公司名称', dataIndex: 'acompany'},
        {header: '用户名', dataIndex: 'auname'},
        {header: '注册日期', dataIndex: 'aregisttime'},
        {header: '可用余额', dataIndex: 'asmsnum'},
        {header: '状态',dataIndex:'aavailable',renderer:addbuttona} //1正常 -1 禁用
    ]);

	function addbuttona(value,e){
		if(1==value){
			return " <button class='btn3_mouseout test' onmouseover=\"this.className='btn3_mouseover test'\" onmouseout=\"this.className='btn3_mouseout test'\" onmousedown=\"this.className='btn3_mousedown test'\" style='cursor: hand;'>禁用</button>";
		}else if(-1==value ){
			return " <button class='btn3_mouseout test' onmouseover=\"this.className='btn3_mouseover test'\" onmouseout=\"this.className='btn3_mouseout test'\" onmousedown=\"this.className='btn3_mousedown test'\" style='cursor: hand;'>启用</button>";
		}else{
		return value;
		}

	}

	var proxygrid = new Ext.grid.GridPanel({
        //title: '代理列表',
       // region: 'center',
        loadMask: true,
        store: proxystore,
        cm: pcolumns,
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: proxystore,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        })
    });

	proxygrid.on('cellclick',function (ngrid, rowIndex, columnIndex, e){
    var record = ngrid.getStore().getAt(rowIndex);   //Get the Record
    var fieldName = ngrid.getColumnModel().getDataIndex(columnIndex); //Get field name

   	if(fieldName == 'aavailable'){
   		   Ext.MessageBox.confirm("提示框", "您确定要禁用代理【"+record.get('acompany')+"】吗？", function(btn){
                if (btn == 'yes') {
                var pid = record.get('aid');

                 Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp',
                  method : 'POST',
                  params : {
                      flag:'cancleproxy',
                      statu:record.get('aavailable'),
                      acompany : record.get('acompany'),
                      auname : record.get('auname'),
                      pid : pid
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								proxygrid.getStore().reload();

                            }
                            else{
                                Ext.Msg.alert('失败','操作失败');
                            }
                         }
              });
                }
            });
   	}
   	});

   	proxygrid.getView().getRowClass = function(record, index){
     		var value = record.data.aavailable;
    		if(value == -1){
				return 'red-row';
			}
       };

    proxystore.load({params:{start:0,limit:15}});
	auto_proxy.on('click', function(){

        if(!winp){
            winp = new Ext.Window({
           		title: '代理列表',
                applyTo     : 'auto-proxy',
                layout      : 'fit',
                width       : 500,
                height      : 400,
                closeAction :'hide',
                plain       : true,
                items       : [proxygrid],

                 buttons: [
					{
                    text     : '关闭',
                    handler  : function(){ winp.hide();}
                    }
				]
            });
        }
        winp.show(auto_proxy);
    });

    //***************************  auto -  user****************************

var userRecord = Ext.data.Record.create([
        {name: 'uids', type: 'string'},
        {name: 'uuname', type: 'string'},
        {name: 'upwd', type: 'string'},
        {name: 'uphone', type: 'string'},
        {name: 'ucompany', type: 'string'},
        {name: 'usmsnum', type: 'int'},
        {name: 'uavailable', type: 'int'},
        {name: 'uregisttime', type: 'string'}

    ]);

    var userstore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/userlist.jsp?flag=autouser'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },userRecord),
        remoteSort: true
    });

    var columns = new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),

        {header: '用户名', dataIndex: 'uuname'},
        {header: '联系方式', dataIndex: 'uphone'},
        {header: '可发信息数', dataIndex: 'usmsnum'},
        {header: '注册日期', dataIndex: 'uregisttime'},
        {header: '状态',dataIndex:'uavailable',renderer:addbuttona} //1正常 -1 禁用
    ]);

	function addbuttona(value,e){
		if(1==value){
			return " <button class='btn3_mouseout test' onmouseover=\"this.className='btn3_mouseover test'\" onmouseout=\"this.className='btn3_mouseout test'\" onmousedown=\"this.className='btn3_mousedown test'\" style='cursor: hand;'>禁用</button>";
		}else if(-1==value ){
			return " <button class='btn3_mouseout test' onmouseover=\"this.className='btn3_mouseover test'\" onmouseout=\"this.className='btn3_mouseout test'\" onmousedown=\"this.className='btn3_mousedown test'\" style='cursor: hand;'>启用</button>";
		}else{
		return value;
		}

	}

    columns.defaultSortable = true;

        var usergrid = new Ext.grid.GridPanel({
        region: 'center',
        loadMask: true,
        store: userstore,
        cm: columns,
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: userstore,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        })
    });

	usergrid.on('cellclick',function (ngrid, rowIndex, columnIndex, e){
    var record = ngrid.getStore().getAt(rowIndex);   //Get the Record
    var fieldName = ngrid.getColumnModel().getDataIndex(columnIndex); //Get field name

   	if(fieldName == 'uavailable'){
   		   Ext.MessageBox.confirm("提示框", "您确定要禁用用户【"+record.get('uuname')+"】吗？", function(btn){
                if (btn == 'yes') {
                 Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp',
                  method : 'POST',
                  params : {
                      flag:'cancleuser',
                      statu:record.get('uavailable'),
                      acompany : record.get('uuname'),
                      auname : record.get('uuname'),
                      pid : record.get('uuname')
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								usergrid.getStore().reload();
                            }
                            else{
                                Ext.Msg.alert('失败','操作失败');
                            }
                         }
              });
                }
            });
		   	}
		   	});

   	   usergrid.getView().getRowClass = function(record, index){
     		var value = record.data.uavailable;
    		if(value == -1){
				return 'red-row';
			}
       };

    userstore.load({params:{start:0,limit:15}});

    auto_user.on('click', function(){

        if(!winu){
            winu = new Ext.Window({
           		title: '用户列表',
                applyTo     : 'auto-user',
                layout      : 'fit',
                width       : 600,
                height      : 400,
                closeAction :'hide',
                plain       : true,
                items       : [usergrid],

                 buttons: [
					{
                    text     : '关闭',
                    handler  : function(){ winu.hide();}
                    }
				]
            });
        }
        winu.show(auto_user);
    });

    <%}%>
});

function doChangeMaxSend(){

   var maxs = document.getElementById('maxsend').value;
   var a = parseInt(maxs);
  	if(isNaN(a)){
  		alert('你输入的为非数字'+maxs);
   	return;
  	}

   Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp',
                  method : 'POST',
                  params : {
                      flag:'maxsend',
                      num:a
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								 document.getElementById('maxsend').value=a;
								 alert('最大单次发送数目已更改为'+a);
                            }
                            else{
                                Ext.Msg.alert('失败','操作失败');
                            }
                         }
              });
}
</script>

    </head>
    <body>
    <br />
        <div id="container">
            <h1>系统管理配置</h1>
            <br />
            <!-- Bread Crumb Code - Be sure to include the chevronOverlay element so we can load the semi transparend png -->
            <div class="breadCrumbHolder module">
                <div id="breadCrumb3" class="breadCrumb module">
                    <ul>
                        <li>
                            <a href="#"></a>
                        </li>
                        <li>
                            <a href="#" id="show-btn">修改密码</a>
                        </li>
                        <li>
                          		 建议经常更换密码，修改密码无需原始密码
                        </li>
                    </ul>
                </div>
            </div>
<%if(username.equals("admin")){ %>
              <div class="breadCrumbHolder module">
                <div id="breadCrumb2" class="breadCrumb module">
                    <ul>
                        <li>
                            <a href="#"></a>
                        </li>
                        <li>
                            <a href="#" id="show-suggest">查看意见或建议</a>
                        </li>
                        <li>
                            	在客户端提供对服务以及产品的意见或建议提交通道，你可以点击这里查看相关信息
                        </li>
                    </ul>
                </div>
            </div>

              <div class="breadCrumbHolder module">
                <div id="breadCrumb1" class="breadCrumb module">
                    <ul>
                        <li>
                            <a href="#"></a>
                        </li>
                        <li>
                            <a href="#" id="auto-pbtn">黑代理</a>
                        </li>
                        <li>
                            您可以将代理设置为禁用状态，该状态将使该代理下的所有用户发送的消息将不被发送到消息网关。
                        </li>
                    </ul>
                </div>
            </div>
            <!-- End Bread Crumb Code -->


             <div class="breadCrumbHolder module">
                <div id="breadCrumb0" class="breadCrumb module">
                    <ul>
                        <li>
                            <a href="#"></a>
                        </li>
                        <li>
                            <a href="#" id="auto-ubtn">黑用户</a>
                        </li>
                        <li>
                            您可以将用户设置为禁用状态，该状态将使该用户发送的消息将不被发送到消息网关。
                        </li>
                    </ul>
                </div>
            </div>
            
              <div class="breadCrumbHolder module">
                <div id="breadCrumb4" class="breadCrumb module">
                    <ul>
                        <li>
                            <a href="#"></a>
                        </li>
                        <li>
                            <a href="#" id="auto-send" onclick="doChangeMaxSend()">设置单次最大发送量</a>
                        </li>
                        <li>
                            <input value="<%=SmsAppContainer.grobleContainer.get("MAX_SEND") %>" size="8" id="maxsend"/>值只能为数字，若设置的数值小于或等于0将不会对任何消息做限制
                        </li>
                    </ul>
                </div>
            </div>
<%} %>
            </div>
            <!-- End Bread Crumb Code -->
<div id="changepassword" class="x-hidden"></div>
<div id="show-suggest-div" class="x-hidden"></div>

<div id="auto-proxy" class="x-hidden"></div>
<div id="auto-user" class="x-hidden"></div>
    </body>
</html>

